package com.lengyu.iottransfer.gateway.security.rest.dto;

import com.lengyu.iottransfer.gateway.entity.User;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.List;

@Data
public class JwtUser  implements UserDetails {

    private String id ;

    private String username;

    private String password;
//
//    private Integer groupId;
//
//    private String groupName;

    //鉴权用的
    private List<GrantedAuthority> authorities;


    public static JwtUser makeJwtUser(User user, String roleNameList) {
        JwtUser jwtUser = new JwtUser();
        jwtUser.id = user.getId();
        jwtUser.username = user.getUsername();
        jwtUser.password = user.getPassword();
        List<GrantedAuthority> auths =
              AuthorityUtils.commaSeparatedStringToAuthorityList(roleNameList);
        jwtUser.authorities = auths;
        return jwtUser;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}